from django.shortcuts import render
from django.http import JsonResponse,HttpResponse
from django.forms.models import model_to_dict

# Create your views here.
from .models import Users

def test(request):
    # 读取数据库数据
    username = request.GET.get('name')
    try:

        res = Users.objects.get(username=username)
        u_dict = model_to_dict(res)

    except:
        u_dict = {
            "username":"Null",
            "password":"Null",
            "email":"Null",
        }
    # for i in res:
    #     print(i.username)
    #     print(i.password)
    #     print(i.email)
    data = {
        "status":'0',
        "message":'this is django projects!!!',
    }
    return JsonResponse(u_dict)